package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.ConnectMySql;
import bean.Login;

/**
 * Servlet implementation class modifyProduct
 */
@WebServlet("/modifyProduct")
public class modifyProduct extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public modifyProduct() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		  PreparedStatement st=null;
	      Connection con=ConnectMySql.getConnection();
	      request.setCharacterEncoding("UTF-8");
	      String dishId=request.getParameter("dishId");
	      String productName=request.getParameter("productName");
	      String price=request.getParameter("price");
	      String catatory=request.getParameter("catatoryId");
	      String picture=request.getParameter("picture");
	      String material=request.getParameter("material");
	      
		  try {
			    request.setCharacterEncoding("UTF-8");
			    response.setContentType("text/html;charset=utf-8");
	            st=con.prepareStatement("update dish set dishName=?,dishPrice=?,catatoryId=?,material=?,imagesRoute=? where dishId=?");
	            st.setString(1,productName);
	            st.setDouble(2,Double.valueOf(price));
	            st.setInt(3,Integer.valueOf(catatory));
	            st.setString(4,material);
	            st.setString(5,picture);
	            st.setInt(6,Integer.valueOf(dishId));
	            st.executeUpdate();
			}catch(SQLException e) {
				e.printStackTrace();
			}
		    response.sendRedirect("login.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
